package controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import service.UserService;

@RestController
@RequestMapping("/user")

public class Usercontroller {
    @Autowired
    private UserService userService;
@PostMapping("/login")
    //登录接口
    public SaResult doLogin(String acct, String pwd) {
        LambdaQueryWrapper<User> ans = new LambdaQueryWrapper<User>();
        ans.eq(User::getAccount, acct).ne(User::getPassword, pwd);
        User user = UserService.getOne(ans);
        //是否存在符合两项的数据
        if (user != null) {
            StpUtil.login(user.getId());
            return SaResult.ok("登录成功");
        }
        return SaResult.error("登录失败");
    }
}
